﻿Public Class SaleOrdExplorer
    Inherits ExplorerTreeList

    Private EditPanePL As PLBase

    Public Sub New(ByVal aQueryName As String)
        MyBase.New(aQueryName)
    End Sub

    Public Sub New()
        MyBase.New()
    End Sub

    Public Overrides Sub PopulateDetailSection(ByVal node As TreeListNode)
        Me.Cursor = Cursors.WaitCursor
        Dim guidEnfant As Guid
        Dim aPLName As String
        Dim aPaneMetaQueryName As String
        Dim aMq As MetaQuery
        '
        If aGridControl IsNot Nothing Then
            aGridControl.Dispose()
            aGridControl = Nothing
        End If
        '
        guidEnfant = DirectCast(node.GetValue(Me.KeyFieldName), Guid)
        aPLName = DirectCast(node.GetValue("PL"), String)
        aPaneMetaQueryName = DirectCast(node.GetValue("MetaQuerie"), String)
        aMq = MetaQuery.GetMetaQueryByName(aPaneMetaQueryName)
        EditPanePL = PLBase.CreateInstanceOf(aPLName, aPaneMetaQueryName)
        aGridControl = New GridExtPL() With {.Dock = DockStyle.Fill, .Pl = EditPanePL, .Name = "SalesOrder", .FormName = PanelName}
        If Not Guid.Empty.Equals(guidEnfant) Then
            EditPanePL.SQLWhere = String.Format("{0} = '{1}'", aMq.GUIDField, guidEnfant)
        End If
        '
        aGridControl.GridActionOptionList.Add(New ActionOption("CustomOption1", "ACT_00126", "Print Order", AddressOf PrintSaleOrder, True, True))

        aGridControl.GridActionOptionList.Add(New ActionOption("CustomOption1", "ACT_00127", "Print Invoice", AddressOf PrintInvoice, True, True))
        aGridControl.GridActionOptionList.Add(New ActionOption("CustomOption1", "ACT_00128", "Print Time Detail", AddressOf PrintTimeDetail, True, True))
        aGridControl.GridActionOptionList.Add(New ActionOption("CustomOption1", "ACT_00129", "Print GO Sale Order", AddressOf PrintGOSaleOrder, True, True))

        aGridControl.GridActionOptionList.Add(New ActionOption("CustomOption2", "ACT_00130", "Link Timesheet", AddressOf LinkTimesheet, True, True))
        aGridControl.GridActionOptionList.Add(New ActionOption("CustomOption2", "ACT_00131", "Unlink Timesheet", AddressOf UnlinkTimesheet, True, True))

        aGridControl.GridActionOptionList.Add(New ActionOption("CustomOption3", "ACT_00132", "Generate Invoice Number", AddressOf GenerateInvoiceNumber, True, True))

        aGridControl.ExpandFirstMasterRow = True

        'On trouve la form pour effacer les controle dedans et ensuite remettre le bon.
        'Comme ca on change le Detail selon la ligne dans L'explorer
        For Each aFrm As XtraForm In Me.ParentForm.MdiChildren
            If aFrm.Name = PanelName Then
                aFrm.Controls.Clear()
                aFrm.Controls.Add(aGridControl)
                aFrm.Show()
                aFrm.Focus()
            End If
            aFrm.Refresh()
        Next
        '
        Me.Cursor = Cursors.Default
    End Sub
End Class
